/**
 * Created by admin on 2016/8/22.
 */
$(function() {
    $('input').placeholder();

    //解析url地址
    var g_id= location.href.substr(location.href.lastIndexOf('/') + 1);
    var studentDetail =
        '<div class="detailTop" data-id="{{items.id}}">' +
        '<p class="title">{{items.title}}</p>' +
        '{{if items.is_alias == 1}}' +
        '<span class="name">{{items.alias}}</span>' +
        '{{else}}' +
        '<span class="name">{{items.performer_name}}</span>' +
        '{{/if}}' +
        '<span class="createTime">{{items.created_at}}</span></br>' +
        '{{if items.is_alias == 1}}' +
        '<span class="secName">姓名：{{items.alias}}</span>' +
        '{{else}}' +
        '<span class="secName">姓名：{{items.performer_name}}</span>' +
        '{{/if}}' +
        '<p class="sCourse">职业：{{items.occupation}}</p>' +
        '<p class="company">公司：{{items.company}}</p>' +
        '{{if items.is_area==1}}' +
        '<p class="salary">地区：保密</p>' +
        '{{else}}' +
        '<p class="salary">地区：{{items.area}}</p>' +
        '{{/if}}' +
        '</div>' +
        '<div class="detailBottom"><!--{{text}}--></div>';
    var yxStudent =
        '<div class="yx">'+
        '{{each items as $value i}}'+
        '<div class="student" data-id="{{$value.id}}">' +
        '<div class="d1 clearfix">' +
        ' 		<span class="d1-img"><img src="{{#changeImg($value.avatar_img)}}"/></span>' +
        ' 	<div class="d1-mess">' +
        '{{if $value.is_alias==1}}'+
        ' 	<p class="d1-name">{{$value.alias}}</p>' +
        '{{else}}'+
        ' 	<p class="d1-name">{{$value.performer_name}}</p>' +
        '{{/if}}'+
        ' 	<p class="d1-job"><span>{{$value.company}}</span>&地区' +
        '{{if $value.is_area==1}}' +
        '<span>保密</span>' +
        '{{else}}' +
        '<span>{{$value.area}}</span>' +
        '{{/if}}' +
        '</p>' +
        ' </div>' +
        ' 		</div>' +
        ' 	<div class="d2 clearfix" data-storyId="{{$value.id}}" style="cursor: pointer;">' +
        ' 	<div class="d2-posi clearfix">' +
        ' 	<div class="d2-posi-ab">' +
        ' 	<span class="d2-img"><img src="{{#changeImg($value.avatar_img)}}"/></span>' +
        '{{if $value.is_alias==1}}'+
        ' 	<p>{{$value.alias}}</p>' +
        '{{else}}'+
        ' 	<p>{{$value.performer_name}}</p>' +
        '{{/if}}'+
        ' 	    				</div>' +
        '     			</div>' +
        '   			<div class="d2-right">' +
        ' 				<p class="d2-job"><span>{{$value.company}}</span>&地区' +
        '{{if $value.is_area==1}}' +
        '<span>保密</span>' +
        '{{else}}' +
        '<span>{{$value.area}}</span>' +
        '{{/if}}' +
        '</p>' +
        ' 			<div class="d2-descr">' +
        ' 			<em>“</em><span>{{$value.introduce}}</span><em>”</em>' +
        ' 	</div>' +
        ' </div>' +
        '  		</div>' +
        ' 	</div>'+
        '{{/each}}'+
        '</div>';


    RequestService("/studentStory/detail", "GET", {id:g_id}, function(data) { //g_idstoryId
        if(data.success == true){
            $("#studentDetail").html(template.compile(studentDetail)({
                items:data.resultObject
            }));
            $(".detailBottom").html(data.resultObject.introduction);
            headerMeta(3,g_id);
            if(listType == 2){
                document.title = data.resultObject.title + " - 博学谷学员故事";
            }
        }else{

        }

    })
    RequestService("/studentStory/listByIndex" , "GET", {gid:g_id}, function (data) {
        $("#student-right").append(template.compile(yxStudent)({
            items:data
        }));
        $(".student").each(function(){
            if($(this).attr("data-id") == g_id){
                $(this).remove();
            }
        })
        $(".d1").each(function(){
            $(this).mouseover(function(){
                $(".d1").css("display","block");
                $(".d2").css("display","none");
                $(this).siblings().css({"position":"fixed","top":"100%","display":"block"});
                var ht=$(this).siblings().find(".d2-right").height();
                $(this).siblings().find(".d2-posi").height(ht);
                $(this).siblings().css({"position":"static","display":"none"});
                $(this).css("display","none").siblings().css({"display":"block"});
            })
        });
        $(".yx").mouseleave(function(){
            $(".d1").css("display","block");
            $(".d2").css("display","none");
        })
        $(".d2").on("click",function(){
            var storyId =$(this).attr("data-storyId");
            if(storyId != $(".detailTop").attr("data-id")){
                window.open(bath+'/web/storyDetail/' + storyId);
            }
        });
    });
})